
/*
'===============================================================================
'  Generated From - BLL_Component_Partial_Core.vbgen
'  
'  This object is partial class component representing a table in a database. It
'  contains core data access methods. Other partial classes should be used for 
'  implementing custom business logic. This class can be regenerated many times.
'  
'  Do not write custom business logic in this class as it will be overwritten 
'  next time the class is generated.
'
'  Version: 1.0
'  Date:	30/01/06
'  Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
'  			DeleteAllWForeignKey, class for sorting.
'===============================================================================
*/
using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    [DataObjectAttribute]
	public partial class vwUnitsAndCoursesInfoComponent
    {
        
		/// <summary>
        /// Default constructor.
        /// </summary>
		public vwUnitsAndCoursesInfoComponent()
        {

        }

	
		/// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<vwUnitsAndCoursesInfo> SelectAll(string sortExpression)
        {
            List<vwUnitsAndCoursesInfo> listvwUnitsAndCoursesInfo = new List<vwUnitsAndCoursesInfo>();
            PlacementManager.DAL.vwUnitsAndCoursesInfo_DAL o = new PlacementManager.DAL.vwUnitsAndCoursesInfo_DAL();

            DataSet ds = o.SelectAll();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listvwUnitsAndCoursesInfo.Add(new vwUnitsAndCoursesInfo((int)row["UnitId"], (string)row["UnitCode"], (string)row["UnitName"], (int)row["DivisionId"], (int)row["YearLevel"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"], (int)row["CourseId"]));
            }
			
			if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }

            listvwUnitsAndCoursesInfo.Sort(new vwUnitsAndCoursesInfoComparer(sortExpression));
            return listvwUnitsAndCoursesInfo;
        }
	}
	
	public class vwUnitsAndCoursesInfoComparer : IComparer<vwUnitsAndCoursesInfo>
    {
        private string _sortColumn;
        private bool _reverse;

        public vwUnitsAndCoursesInfoComparer(string sortExpression)
        {
            _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
            if (_reverse)
            {
                _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
            }
            else
            {
                _sortColumn = sortExpression;
            }
        }

        public int Compare(vwUnitsAndCoursesInfo a, vwUnitsAndCoursesInfo b)
        {
            int retVal = 0;
            switch (_sortColumn)
            {
				case "UnitId":
					retVal = String.Compare(a.UnitId.ToString(), b.UnitId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UnitCode":
					retVal = String.Compare(a.UnitCode.ToString(), b.UnitCode.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UnitName":
					retVal = String.Compare(a.UnitName.ToString(), b.UnitName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DivisionId":
					retVal = String.Compare(a.DivisionId.ToString(), b.DivisionId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "YearLevel":
					retVal = String.Compare(a.YearLevel.ToString(), b.YearLevel.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsActive":
					retVal = String.Compare(a.IsActive.ToString(), b.IsActive.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateCreated":
					retVal = String.Compare(a.DateCreated.ToString(), b.DateCreated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CreatedBy":
					retVal = String.Compare(a.CreatedBy.ToString(), b.CreatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateUpdated":
					retVal = String.Compare(a.DateUpdated.ToString(), b.DateUpdated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UpdatedBy":
					retVal = String.Compare(a.UpdatedBy.ToString(), b.UpdatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CourseId":
					retVal = String.Compare(a.CourseId.ToString(), b.CourseId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;

            }
            return (retVal * (_reverse ? -1 : 1));
        }
    }
}
	
